package com.example.onlineeducation.viewmodel

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.baidu.location.BDAbstractLocationListener
import com.baidu.location.BDLocation
import com.baidu.location.LocationClient
import com.baidu.location.LocationClientOption
import com.example.onlineeducation.base.BaseViewModel
import com.example.onlineeducation.utils.BaiduLocationUtil
import com.yc.jetpacklib.extension.ycLogDSimple
import com.yc.jetpacklib.extension.ycLogE

/**
 * Creator: yc
 * Date: 2022/5/5 13:43
 * UseDes:
 */
class BaiduLocationVM : BaseViewModel() {

    private val mBaiduLocationUtil by lazy { BaiduLocationUtil() }

    private val _mBDLocation = MutableLiveData<BDLocation?>()
    val mBDLocation: LiveData<BDLocation?> = _mBDLocation
    fun initLocation(context: Context) {
        mBaiduLocationUtil.initLocation(context)
        mBaiduLocationUtil.mResult = {
            _mBDLocation.postValue(it)
        }
    }

    fun start() {
        mBaiduLocationUtil.start()
    }

    fun stop() {
        mBaiduLocationUtil.stop()
    }

    override fun onCleared() {
        stop()
        super.onCleared()
    }
}